package com.itheima.sh;

import com.itheima.sh.rule.MyRule;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@EnableDiscoveryClient
public class ConsumerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.class, args);
        System.out.println("同一个consumer-111");
    }

    // 注册RestTemplate的对象到Spring的容器中
    @Bean   //通过打印信息可知，bean是优先注入的。
    @LoadBalanced
    public RestTemplate restTemplate() {
        System.out.println("同一个consumer-222");
        return new RestTemplate();
    }

    @Bean
    public IRule rule() {
//        return new RandomRule();
        return new MyRule();
    }

}
